package org.samples.test;

import java.util.Date;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.samples.dao.IExamUserDAO;
import org.samples.model.ExamUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"file:WebContent/WEB-INF/viewspace-servlet.xml"})
public class UserTEST {

	@Autowired
	private IExamUserDAO userDAO;
	
	@Test
	public void testFindAllUsers() {
		List<ExamUser> userList = userDAO.findUserPage().getDates();
		for(ExamUser user : userList){
			System.out.println(user.getUserName());
		}
	}
	
	@Test
	public void testFindByID() {
		ExamUser user = userDAO.getById("2");
		System.out.println(user.getUserName());
	}

	@Test
	public void testCreatUser() throws Exception {
		ExamUser user = new ExamUser();
		user.setUserId("11");
		user.setUserName("test");
		user.setBirthday(new Date().toString());
		userDAO.creatUser(user);
		System.out.println("已插入数据");
	}
	
	@Test
	public void testEditUser() throws Exception {
		ExamUser user = new ExamUser();;
		user.setUserId("1");
		user.setUserName("test");
		userDAO.editUser(user);
		System.out.println("已更新数据");
	}
	
	@Test
	public void testDeleteUser() throws Exception {
		userDAO.deleteUser("1");
		System.out.println("已删除数据");
	}
	
}
